import 'package:get_storage/get_storage.dart';
import 'package:gt_flutter_admin/models/index.dart';

import '../constant/storage_key.dart';

class StorageUtils {
  /// 用户是否登录
  static bool isLogin() {
    String? token = GetStorage().read(Storages.TOKEN);

    return token?.isNotEmpty ?? false;
  }

  /// 保存 token
  static void writeToken(String token) {
    GetStorage().write(Storages.TOKEN, token);
  }

  /// 读取 token
  static String? readToken() {
    return GetStorage().read(Storages.TOKEN);
  }

  /// 删除 token
  static void removeToken() {
    GetStorage().remove(Storages.TOKEN);
  }

  /// 保存用户
  static void writeUser(User user) {
    GetStorage().write(Storages.USER, user);
  }

  /// 读取用户
  static User? readUser() {
    return GetStorage().read(Storages.USER);
  }
}
